package com.yonyou.iuap.ipaas.connector.sdwcoatencent.internal.utils;

import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.json.JSONUtil;
import com.yonyou.iuap.ipaas.connector.sdwcoatencent.api.model.core.constant.CommonConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 日志工具类
 */
public class LogUtils {
	
	private static final Logger logger = LoggerFactory.getLogger(LogUtils.class);
	
	public static final String LINKER_CODE = "sdwc-oa-tencent";
	
	private LogUtils() {
	}
	
	/**
	 * 连接器操作-入口日志打印
	 */
	public static <T> void start(String apiUri, T body) {
		logger.error("【start】【连接器编码】linker_code:{},【操作API】apiUri={} 【请求参数】{}", LINKER_CODE, apiUri, JSONUtil.toJsonStr(body));
	}
	
	public static <T> void apiInfo(String apiUri, String resInfo) {
		logger.error("【apiInfo】【连接器编码】linker_code:{},【操作API】apiUri={},{})", LINKER_CODE, apiUri, resInfo);
	}
	
	/**
	 * 连接器操作-出口日志打印
	 */
	public static <T> void end(String apiUri, T output) {
		logger.error("【end】【连接器编码】linker_code:{},【操作API】apiUri={} 【返回结果】Result.output={}", LINKER_CODE, apiUri, JSONUtil.toJsonStr(output));
	}
	
	public static void printStacktrace(Exception e) {
		logger.error("[exception]>>>linker_code:{},stacktrace info:{}", LINKER_CODE, ExceptionUtil.stacktraceToString(e));
	}
	
	public static <T> void apiRequestInfo(String url, T requestParam) {
		logger.error("[apiInfo]>>>linker_code:{},url:{},param:{}", new Object[] { CommonConstant.LINKER_CODE, url, requestParam });
	}
	
	public static void apiResponseInfo(String url, String resultInfo) {
		logger.error("[apiInfo]>>>linker_code:{},url:{},result:{}", new Object[] { CommonConstant.LINKER_CODE, url, resultInfo });
	}
	
	
}
